function location() {}

location.prototype.getLocation = function() {
	return new Promise((resolve,inject) =>{
		uni.getSetting({
			success: (res) => {
				// res.authSetting['scope.userLocation'] == undefined    表示 初始化进入该页面
				// res.authSetting['scope.userLocation'] == false    表示 非初始化进入该页面,且未授权
				// res.authSetting['scope.userLocation'] == true    表示 地理位置授权
				if (res.authSetting['scope.userLocation'] == false) {
					uni.showModal({
						title: '人在海南请求授权定位当前位置',
						content: '需要获取您的地理位置，以便给您获取附近信息',
						success: res => {
							if (res.cancel) {
								inject();
								uni.showToast({
									title: '您已拒绝授权获取当前位置',
									icon: 'none',
									duration: 1000
								})
							} else if (res.confirm) {
								uni.openSetting({
									success: (dataAu) => {
										if (dataAu.authSetting["scope.userLocation"] == true) {
											uni.getLocation({
											 type:'gcj02',
											 success:(e)=>{
												 resolve({
													 latitude:e.latitude, //维度
													 longitude:e.longitude //精度
												 })
											 },
											 fail: (e) => {
											
											 }
											});
										} else {
											inject();
											uni.showToast({
												title: '您已拒绝授权获取当前位置',
												icon: 'none',
												duration: 1000
											});
										
}									}
								})
							}
						}
					})
				}else {
					uni.getLocation({
						type:'gcj02',
						success:(e) =>{
							resolve({
								 latitude:e.latitude, //维度
								 longitude:e.longitude //精度
								})
							},
						fail:(e) =>{
								inject();
						}
					})
				}
			}
		});
	})
}

export default new location();

